package com.dman.multi.cmd;

import org.apache.pivot.collections.List;
import org.apache.pivot.wtk.TableView;

import com.dman.multi.core.Download;

public class GUIMoveCommand implements Command {
	
	private List<Download> downloadList;
	private TableView tableView;
	private boolean isPrev;
	
	public GUIMoveCommand(TableView tableView, List<Download> downloadList, boolean isPrev) {
		this.downloadList = downloadList;
		this.tableView = tableView;
		this.isPrev = isPrev;
	}

	@Override
	public void execute() {
		int index = tableView.getSelectedIndex();
		if(index >= 0){
			synchronized (downloadList) {
				if(isPrev && index > 0)
					--index;
				if(!isPrev && index < downloadList.getLength() - 1)
					++index;
			}
		}
		tableView.setSelectedIndex(index);
	}
}
